/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ntb.common;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Thinh Hung
 */
public class StringUtil {

    public StringUtil() {
    }
    // used to generate MD5 hash of a string
    public String generateMD5(String str) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes());
            BigInteger dis = new BigInteger(1, md5.digest());
            str = dis.toString(16);
            return str;
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(StringUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public String generateRandomString() {
        SecureRandom random = new SecureRandom();
        //String str = new BigInteger(130, random).toString(32);
        String str = new BigInteger(50, random).toString(32);
        return str;
    }
}
